Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose fix for connection testing issues in Cloud. #836

Merged

Conversation

VersusFacit
Copy link
Contributor

@VersusFacit VersusFacit commented Oct 24, 2024

Description

dbt cloud has a feature for testing connections. It and other features are currently failing due to adapter behavior flags not being registered for those runs.

If we look at these lines, we see the use of a flag in the adapter class init. This was par t of #808

    def __init__(self, config: Any, mp_context: SpawnContext) -> None:
        super().__init__(config, mp_context)
        if self.behavior.use_info_schema_for_columns.no_warn:  # type: ignore[attr-defined]
            self.get_column_behavior = GetColumnsByInformationSchema()
        else:
            self.get_column_behavior = GetColumnsByDescribe()

This is not guaranteed to succeed. So we can use exception handling to ensure the control flow for other subtasks where the flags won't be registered are handled gracefully.

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

try:
if self.behavior.use_info_schema_for_columns.no_warn: # type: ignore[attr-defined]
self.get_column_behavior = GetColumnsByInformationSchema()
except CompilationError:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we didn't expect behavior flags to be used this early in the runtime, so we need an extra check for the use here that protects against situations where flags don't get registered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this condition into get_columns_in_relation. It looks like that's the only thing that references self.get_column"_behavior (at least in the adapter itself). And if we're at that point, then we definitely have flags from project.yml. This also aligns with pushing behavior flags as close to their relevant code as possible. While column metadata is a part of the vast majority of runs, we should still strive to keep the flag close to the code that it impacts, that way when we remove the flag we have a better idea of what we're affecting.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not defined by init time? In general I try to follow the pattern of https://blog.ploeh.dk/2011/07/28/CompositionRoot/, but man does dbt make that difficult. I would strongly prefer not to delay selecting behavior until get_columns_in_relation. I am fine with @VersusFacit's suggestion, but don't really understand why the initialization behavior is not the same for all paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We took this thread to a more rapid response forum but for posterity project flags come from the dbt_project.yml which cloud doesn't always have in scope for certain workflows. So for that situation, we pass a dummy dbt_project.yml (empty of flags) and use profiles.yml / the cloud equivalent to, say, connection test.

benc-db
benc-db previously approved these changes Oct 24, 2024
try:
if self.behavior.use_info_schema_for_columns.no_warn: # type: ignore[attr-defined]
self.get_column_behavior = GetColumnsByInformationSchema()
except CompilationError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not defined by init time? In general I try to follow the pattern of https://blog.ploeh.dk/2011/07/28/CompositionRoot/, but man does dbt make that difficult. I would strongly prefer not to delay selecting behavior until get_columns_in_relation. I am fine with @VersusFacit's suggestion, but don't really understand why the initialization behavior is not the same for all paths.

@benc-db benc-db merged commit da3a9f9 into databricks:main Oct 24, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants